package com.itheima.Jiuye15;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ServerDemo01 {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(1000);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2,    //核心线程数
                5,    //线程池最大线程数
                60,   //闲置线程存活时间
                TimeUnit.SECONDS,     //闲置线程存活时间单位
                new ArrayBlockingQueue<>(5),//阻塞队列
                Executors.defaultThreadFactory(),    //创建线程的方式，默认方式
                new ThreadPoolExecutor.AbortPolicy());    //拒绝策略
        //等待客户端连接
        while (true) {
            Socket accept = serverSocket.accept();
            ThreadSoket ts = new ThreadSoket(accept);
            //new Thread(ts).start();
            pool.submit(ts);
        }
       // serverSocket.close();
    }
}
